package com.example.controller;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @author fyxw
 */
@Controller
@RequestMapping("/time")
public class TimeController {
    @RequestMapping("/getTime")
    @ResponseBody
    public String  getTime() {
        return LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
    }

    @RequestMapping("/setTime")
    @ResponseBody
    public String setTime(@DateTimeFormat(pattern = "yyyy-MM-dd") Date time) {
        return time.toString();
    }
}
